﻿// Copyright richyp 2009
using System;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using Richyp.Bodger.Parser;
namespace Richyp.Bodger {
    public class CodexFile : ParsedDocument {
        private XmlDocument rawData;
        public XmlDocument RawData {
            get {
                return this.rawData;
            }
            set {
                this.rawData = value;
            }
        }

        public string Path { get; set; }
        public String Name { get; set; }
        public String UserListName { get; set; }
        public String Author { get; set; }
        public String Version { get; set; }
        public String System { get; set; }
        public GameSystem GameSystem { get; set; }
        private List<SpecialRule> specialRules = new List<SpecialRule>();
        public List<SpecialRule> SpecialRules {
            get {
                return this.specialRules;
            }
        }
        private List<Wargear> wargear = new List<Wargear>();
        public List<Wargear> Wargear {
            get {
                return this.wargear;
            }
        }

        public Wargear GetWargearByName(string name) {
            foreach (Wargear item in wargear) {
                if (item.Name.ToUpper() == name.ToUpper()) {
                    return item;
                }
            }
            return null;
        }

        public Wargear GetWargearByID(int id) {
            foreach (Wargear item in wargear) {
                if (item.ID == id) {
                    return item;
                }
            }
            return null;
        }
        private List<WargearGroup> wargearGroups = new List<WargearGroup>();
        public List<WargearGroup> WargearGroups {
            get {
                return this.wargearGroups;
            }
        }

        public WargearGroup GetWargearGroupByName(string name) {
            foreach (WargearGroup group in this.wargearGroups) {
                if (group.Name.ToUpper() == name.ToUpper()) {
                    return group;
                }
            }
            return null;
        }

        public WargearGroup GetWargearGroupByID(int id) {
            foreach (WargearGroup group in this.wargearGroups) {
                if (group.ID == id) {
                    return group;
                }
            }
            return null;
        }
        private List<BaseUnit> baseUnits = new List<BaseUnit>();
        public List<BaseUnit> BaseUnits {
            get {
                return this.baseUnits;
            }
        }

        public BaseUnit GetBaseUnitByName(string name) {
            foreach (BaseUnit unit in this.baseUnits) {
                if (unit.Name.ToUpper() == name.ToUpper()) {
                    return unit;
                }
            }
            return null;
        }

        public BaseUnit GetBaseUnitByID(int id) {
            foreach (BaseUnit unit in this.baseUnits) {
                if (unit.ID  == id) {
                    return unit;
                }
            }
            return null;
        
        }

        private List<CodexEntry> codexEntries = new List<CodexEntry>();
        public List<CodexEntry> CodexEntries {
            get {
                return this.codexEntries;
            }
        }

        public CodexEntry GetEntryByName(string name) {
            foreach (CodexEntry entry in this.codexEntries) {
                if (entry.Name.ToUpper() == name.ToUpper()) {
                    return entry;
                }
            }
            return null;
        }

        public CodexEntry GetEntryByID(int id) {
            foreach (CodexEntry entry in this.codexEntries) {
                if (entry.ID == id) {
                    return entry;
                }
            }
            return null;
        
        }

        private List<Unit> transports = new List<Unit>();
        public List<Unit> Transports {
            get {
                return this.transports;
            }
        }

        private List<ArmouryItem> armoury = new List<ArmouryItem>();
        public List<ArmouryItem> Armoury
        {
            get { return this.armoury; }
        }

        public Unit GetTransportByName(string name) {
            foreach (Unit unit in this.transports) {
                if (unit.Name.ToUpper() == name.ToUpper()) {
                    return unit;
                }
            }
            return null;
        }

        public CodexEntry this[string name] {
            get {
                return this.GetEntryByName(name);
            }
        }

        public CodexEntry this[int id] {
            get {
                return this.GetEntryByID(id);
            }
        }

        
    }

   
}
